//
//  AppDelegate+IsVersion.m
//  OC-微博
//
//  Created by Apple on 15/11/13.
//  Copyright © 2015年 Apple. All rights reserved.
//

#import "AppDelegate+IsVersion.h"
#import "UserAccountViewModel.h"
#import "NewFeatureController.h"
#import "MainViewController.h"
#import "WelcomeViewController.h"
@implementation AppDelegate (IsVersion)
#pragma mark /*******************  通知  *******************/
- (void)notification{
[[NSNotificationCenter defaultCenter]
 addObserverForName:WBSwitchRootViewControllerNotification  // 通知名称，通知中心用来识别通知的
 object:nil                                          // 发送通知的对象，如果为nil，监听任何对象
 queue:nil                                             // nil，主线程
 usingBlock:^(NSNotification * _Nonnull note) {
     //切换控制器
     UIViewController *vc =  note.object != nil ? [WelcomeViewController new]:[MainViewController new];
     NSLog(@"%@sss",note);
    [UIApplication sharedApplication].keyWindow.rootViewController = vc;
 }];
    
}
#pragma mark /*******************  界面切换代码  *******************/
- (UIViewController *)defaultViewController {
 //判断是否登录
    if([UserAccountViewModel shardViewModel].userlogin) {
    
        return self.isVersion ? [NewFeatureController new] :[WelcomeViewController new];
    }
    return  [MainViewController new];
}
#pragma mark /*******************  判断版本号  *******************/
//  CFBundleVersion
- (BOOL)isVersion {
    //获取当前版本  info.plist
    NSString *NewVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
    NSLog(@"当前版本号：%@", NewVersion);
    //之前版本号 存储在本地的版本号
    NSString *oldVersion = [[NSUserDefaults standardUserDefaults] objectForKey:sanBox];
    NSLog(@"之前版本号%@", oldVersion);
    //存储版本号
    [[NSUserDefaults standardUserDefaults]setObject:NewVersion forKey:sanBox];
    //返回比较
    // NSLog(@"%ld", [NewVersion compare:oldVersion]);
    return [NewVersion compare:oldVersion];
}
#pragma mark /*******************  设置tabbar颜色  *******************/
- (void)setupAPPearance {
    UINavigationBar *tab = [UINavigationBar appearance];
    tab.tintColor = wbcolor;
    UITabBar *tb = [UITabBar appearance];
    tb.tintColor = wbcolor;
    
}

@end
